home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / cross < prev    next >
Text File  |  1994-09-23  |  586b  |  25 lines

  1. //-------------------------------------------------------------------//
  2. //  Syntax:    cross ( A , B )
  3. //
  4. //  Description:
  5.  
  6. //  Given A and B (two 1-by-3 matrices), compute the vector
  7. //  cross-product.
  8. //-------------------------------------------------------------------//
  9.  
  10. cross = function(v1, v2) 
  11. {
  12.   if(v1.n != 3 || v2.n != 3) 
  13.   { 
  14.     printf("cross product requires 3-length matrices\n");
  15.     return 0;
  16.   }
  17.  
  18.   tmp = zeros(1,3);
  19.   tmp[1] =  ((v1[2]*v2[3]) - (v1[3]*v2[2]));
  20.   tmp[2] = -((v1[1]*v2[3]) - (v1[3]*v2[1]));
  21.   tmp[3] =  ((v1[1]*v2[2]) - (v1[2]*v2[1]));
  22.  
  23.   return tmp;
  24. };
  25.